package xyz.scootaloo.oj.iq

import org.junit.Test
import xyz.scootaloo.console.app.support.Tester

/**
 * @author flutterdash@qq.com
 * @since 2021/4/14 23:09
 */
class M0101 {

    fun isUnique(astr: String): Boolean {
        if (astr.length > 26) return false
        val cache = BooleanArray(26)
        for (c in astr) {
            val pos = c - 'a'
            if (cache[pos])
                return false
            cache[pos] = true
        }
        return true
    }

    /**
     * 001000
     * 010000
     * 000000
     *
     * 001000
     * 001000
     * 001000
     *
     * 001
     * 001
     */
    fun case0(astr: String): Boolean {
        if (astr.length > 26)
            return false
        var mark = 0
        val base = 1
        for (c in astr) {
            val offset = base.shl(c - 'a')
            if (mark.and(offset) != 0)
                return false
            mark = mark.or(offset)
        }
        return true
    }

    @Test
    fun test0() {
        Tester.createTest(this::isUnique)
            .addCase("leetcode", false)
            .addCase("abc", true)
            .testAndShow()
        Tester.createTest(this::case0)
            .addCase("leetcode", false)
            .addCase("abc", true)
            .testAndShow()
    }

    @Test
    fun test1() {
        val num1 = 1
        val num2 = 1
        println(num1.or(num2))
    }

}
